﻿using System;
using System.Runtime.InteropServices;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
using Microsoft.SharePoint.Utilities;
using System.Configuration;

namespace SJKP.PDFConversion.Client
{
    [Guid("09c8572a-0c52-4371-a683-54427c04d24b")]
    public class OCRServiceApplicationProxy : SPIisWebServiceApplicationProxy
    {
        public OCRServiceApplicationProxy() 
        {}

        [Persisted] 
        private SPServiceLoadBalancer loadBalancer;

        public OCRServiceApplicationProxy(string name, OCRServiceProxy ocrServiceProxy, Uri uri) : base(name,ocrServiceProxy,uri)
        {
            loadBalancer = new SPRoundRobinServiceLoadBalancer(uri);
        }

        public override string TypeName
        {
            get
            {
                return "OCR Service Application Proxy";
            }
        }

        public override void Provision()
        {
            loadBalancer.Provision();
            base.Provision();
        }

        public override void Unprovision(bool deleteData)
        {
            loadBalancer.Unprovision();
            base.Unprovision(deleteData);
        }

        public Configuration Configuration
        {
            get
            {
                return OpenClientConfiguration(SPUtility.GetGenericSetupPath(@"WebClients\SJKP.OCR"));
            }
        }

        public SPServiceLoadBalancer LoadBalancer
        {
            get { return loadBalancer; }
        }
    }
}
